package operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation {
    public void work(BookList booklist) {
        System.out.println("删除图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要删除的书名");
        String name = scanner.nextLine();
        int index=-1;
        for (int i = 0; i < booklist.getsize(); i++) {
            if (booklist.getbook(i).getName().equals(name)) {
                index=i;
            }
        }
        if(index ==-1) {
            System.out.println("要删除的书不存在");
        }else {
            for (int i = index; i < booklist.getsize()-1; i++) {
                booklist.setBook(i);
            }
        }
        Book book=booklist.getbook(booklist.getsize()-1);
        book=null;
        booklist.setsize(booklist.getsize()-1);

    }
}
